package de.wbh.gwt.form.layouter.gwt.ui.view.widget;

import com.google.gwt.core.client.GWT;
import com.google.gwt.resources.client.ClientBundle;
import com.google.gwt.resources.client.CssResource;
import com.google.gwt.user.client.ui.FocusPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.SimplePanel;

public class Field extends FocusPanel {

	public static interface Resources extends ClientBundle {

		static interface Style extends CssResource {
			String dropped();

			String field();
		}

		@Source("field.css")
		Style style();

	}

	private final SimplePanel panel = new SimplePanel();

	private String id;

	private final Resources resources;

	public Field(Resources resources, String id) {
		setWidget(this.panel);
		addStyleName(resources.style().field());
		this.resources = resources;
		resources.style().ensureInjected();

		Label label = new Label(this.id = id);
		this.panel.setWidget(label);
	}

	public Field(String id) {
		this(GWT.<Resources> create(Resources.class), id);
	}

	public String getId() {
		return this.id;
	}

	@Override
	public void removeFromParent() {
		super.removeFromParent();
	}

	public void setDropped(boolean dropped) {
		if (dropped) {
			addStyleName(this.resources.style().dropped());
		} else {
			removeStyleName(this.resources.style().dropped());
		}
	}

}
